package wah;

import static org.junit.Assert.assertTrue;
import wah.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Tests that WahibRobot fires bullets with high max power against RamFire robot.
 * @author Wahib Hanani
 *
 */
public class TestWahibRobotFiring extends RobotTestBed {
  /** True if the robot fire bullets with max power during the test case. */
  boolean fireMaxPower = false;
  
  /**
   * Specifies that RamFire and WahibRobot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.RamFire,wah.WahibRobot";
  }
  
  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if the distance between WahibRobot and RamFire 
   * is less than 150 to shot max power bullets.  If so, set the corresponding flag.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    IRobotSnapshot enemy = event.getTurnSnapshot().getRobots()[0];
    double rxPos = robot.getX(); 
    double exPos = enemy.getX();
    double distance;
    distance = rxPos - exPos;
    if (distance < 0) {
      distance = -1 * distance;
    }

    if (distance <= 150) {
      fireMaxPower = true;
    }
  
  }  
  /**
   * After the battle, check to see that we've fired bullets with max power. 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check fire with Max power", fireMaxPower);
     
  }

}
